<template>
  <view class="container" style="padding: 20px">
    <li-form>
      <li-form-item label="action">
        <li-textarea v-model="form.action"></li-textarea>
      </li-form-item>
      <li-form-item label="params">
        <li-textarea v-model="form.params"></li-textarea>
      </li-form-item>
    </li-form>

    <view style="margin: 10px 0">
      <button @click="sendRequest" type="primary">发送请求</button>
    </view>

    <textarea
      style="height: 300px"
      :maxlength="-1"
      v-model="resp"
    ></textarea>
  </view>
</template>
<script>
import { baseURLWebApi } from "../../../utils/env";
import { uGetStorageSync } from "../../../utils/uniUtils";

export default {
  data() {
    return {
      resp: "{}",
      form: {
        action: "eleme.user.getUser",
        params: "{}",
      },
    };
  },

  methods: {
    sendRequest() {
      let header = {};
      const token = uGetStorageSync("token");

      if (token) {
        header["Authorization"] = `Bearer ${token}`;
      }

      let that = this;
      uni.request({
        url: `${baseURLWebApi}/api/eleme/ElemeRPC`,
        header,
        data: {
          ...that.form,
          ...{
            params: JSON.parse(that.form.params),
          },
        },
        method: "POST",
        success(res) {
          that.resp = JSON.stringify(res.data);
        },
      });
    },
  },
};
</script>
